<div class="real-contents all-contents">
	<div class="clearfix">
		<span class="rectangle"></span>
		<span class="title">浏览习题</span>
	</div>
	<div id="activities-ajax-result">
		<table class="show-table show-table-activities">
			<tr class="show-tr">
				<th>正在加载活动信息...</th>
			</tr>
		</table>
	</div>
	<ul class="input-ul">
		<li class="input-li">
			<button type="button" class="input-border-no-radius page-margin" id="firstPage">首页</button>
			<button type="button" class="input-border-no-radius" id="previousPage">上一页</button>
			<button type="button" class="input-border-no-radius" id="nextPage">下一页</button>
			<button type="button" class="input-border-no-radius" id="lastPage">尾页</button>
			<span class="input-title middle-input-title" style="letter-spacing: 2px">
				当前第
				<span id="nowpagecopy">1</span>
				页，共
				<span id="totalpagescopy">1</span>
				页，到第
			</span>
			<span class="input-border-no-radius kkkkkk">
				<input type="text" name="toPgae" class="input-text input-number" value="1" maxlength="3" />
			</span>
			<span class="input-title middle-input-title"> 页</span>
			<button type="button" class="input-border-no-radius middle-input-title" id="toPage-button">确定</button>
		</li>
	</ul>
</div>
<script type="text/javascript">
$(function(){

	$.ajax({
		type:'post',
		url:"/SmartClass/taskAJAX/queryTask",
		async: false,
		success: function(data) {
			$("#activities-ajax-result").html(data);
		}
	});
	
	//以下是翻页相关逻辑
	
	$(".kkkkkk").click(function(){
		$("[name='toPgae']").focus();
	});
	
	$("#nowpagecopy").text($("#nowPage").text());
	$("#totalpagescopy").text($("#totalPages").text());
	
	//翻页逻辑
	function page_ajax(nowPage,totalPages){
		$.ajax({
			url:"/SmartClass/taskAJAX/queryTask",
			async:false,
			type:"POST",
			data:{
				"nowPage":nowPage
			},
			success:function(data){
				//alert_text(a);
				$("#activities-ajax-result").html(data);
			}
		});
		$("#nowpagecopy").text(nowPage);
		$("#totalpagescopy").text(totalPages);
		
		$("#lastPage").removeAttr("disabled");
		$("#nextPage").removeAttr("disabled");
		$("#firstPage").removeAttr("disabled");
		$("#previousPage").removeAttr("disabled");
		
		if(nowPage == 1){
			$("#firstPage").attr("disabled",true);
			$("#previousPage").attr("disabled",true);
		}
		
		if(nowPage == totalPages){
			$("#lastPage").attr("disabled",true);
			$("#nextPage").attr("disabled",true);
		}
	}
	
	//下一页
	$('#nextPage').click(function(){
		var nowPage = parseInt($("#nowPage").text());
		var totalPages = parseInt($("#totalPages").text());
		
		if(nowPage < totalPages) {
			nowPage = nowPage + 1;
		}
		
		page_ajax(nowPage,totalPages);
	});
	
	//上一页
	$('#previousPage').click(function(){
		var nowPage = parseInt($("#nowPage").text());
		var totalPages = parseInt($("#totalPages").text());
		
		if(nowPage > 1) {
			nowPage--;
		}
		
		page_ajax(nowPage,totalPages);
	});
	
	//首页
	$('#firstPage').click(function(){
		var nowPage = parseInt($("#nowPage").text());
		var totalPages = parseInt($("#totalPages").text());
		
		nowPage = 1;
		
		page_ajax(nowPage,totalPages);
	});
	
	//尾页
	$('#lastPage').click(function(){
		
		var totalPages = parseInt($("#totalPages").text());
		
		var nowPage = totalPages;
		
		page_ajax(nowPage,totalPages);
	});
	
	//指定页
	$('#toPage-button').click(function(){
	
		var toPage = parseInt($("[name='toPgae']").val());
		var nowPage = parseInt($("#nowPage").text());
		var totalPages = parseInt($("#totalPages").text());
		
//		alert_text(toPage+" "+nowPage+" "+totalPages);
		
		if(toPage == nowPage) {
			return;
		} else if(toPage < 1 || toPage > totalPages) {
			alert_text("warning","输入页码范围要在 1-"+totalPages+" 之间");
		} else if(isNaN(toPage)) {
			alert_text("warning","输入页码应为数字");
		} else {
			nowPage = toPage;
		}
		
		page_ajax(nowPage,totalPages);
	});
	
	var nowPage = parseInt($("#nowPage").text());
	var totalPages = parseInt($("#totalPages").text());
	
	$("#lastPage").removeAttr("disabled");
	$("#nextPage").removeAttr("disabled");
	$("#firstPage").removeAttr("disabled");
	$("#previousPage").removeAttr("disabled");
	
	if(nowPage == 1){
		$("#firstPage").attr("disabled",true);
		$("#previousPage").attr("disabled",true);
	}
	
	if(nowPage == totalPages){
		$("#lastPage").attr("disabled",true);
		$("#nextPage").attr("disabled",true);
	}
	
});


</script>